803833b8: 27 bd ff d8  ADDIU sp, sp, 0xffffffd8 (-40)
803833bc: af bf 00 14  SW ra, sp, 0x14 (20)
803833c0: af a4 00 28  SW a0, sp, 0x28 (40)
803833c4: af a5 00 2c  SW a1, sp, 0x2c (44)
803833c8: af a6 00 30  SW a2, sp, 0x30 (48)
803833cc: af a7 00 34  SW a3, sp, 0x34 (52)

803833d0: 3c 01 80 36  LUI at, 0x8036 (32822)
803833d4: ac 20 11 84  SW r0, at, 0x1184 (4484)            *(0x80361184) = 0;

803833d8: 3c 01 80 39  LUI at, 0x8039 (32825)
803833dc: ac 20 be 90  SW r0, at, 0xffffbe90 (-16752)      *(0x8038be90) = 0;

803833e0: 3c 01 80 36  LUI at, 0x8036 (32822)
803833e4: ac 20 11 6c  SW r0, at, 0x116c (4460)            *(0x8036116c) = 0;

803833e8: 3c 01 80 36  LUI at, 0x8036 (32822)
803833ec: ac 20 11 70  SW r0, at, 0x1170 (4464)            *(0x80361170) = 0;

803833f0: 0c 0e 09 74  JAL 0x803825d0 (-2143803952)        0x803825d0();
803833f4: 00 00 00 00  NOP

803833f8: 8f ae 00 2c  LW t6, sp, 0x2c (44)
803833fc: 85 cf 00 00  LH t7, t6, 0x0 (0)
80383400: a7 af 00 26  SH t7, sp, 0x26 (38)                [sp + 0x26] = *[sp + 0x2c]

80383404: 8f b8 00 2c  LW t8, sp, 0x2c (44)
80383408: 27 19 00 02  ADDIU t9, t8, 0x2 (2)
8038340c: af b9 00 2c  SW t9, sp, 0x2c (44)                [sp + 0x2c] += 2;

80383410: 87 a8 00 26  LH t0, sp, 0x26 (38)
80383414: 29 01 00 40  SLTI at, t0, 0x40 (64)
80383418: 10 20 00 08  BEQ r0, at, 0x8038343c (pc + 0x20)  if ([sp + 0x26] >= 0x40) goto 0x8038343c; /* if ([sp + 0x26] < 0x40) { */
8038341c: 00 00 00 00  NOP

80383420: 27 a4 00 2c  ADDIU a0, sp, 0x2c (44)
80383424: 8f a5 00 20  LW a1, sp, 0x20 (32)
80383428: 87 a6 00 26  LH a2, sp, 0x26 (38)
8038342c: 0c 0e 0c 1a  JAL 0x80383068 (-2143801240)        0x80383068(&[sp + 0x2c], [sp + 0x20], [sp + 0x26], &[sp + 30]);
80383430: 27 a7 00 30  ADDIU a3, sp, 0x30 (48)

80383434: 10 00 00 35  BEQ r0, r0, 0x8038350c (pc + 0xd4)  goto 0x8038350c; /* } else { */
80383438: 00 00 00 00  NOP

8038343c: 87 a9 00 26  LH t1, sp, 0x26 (38)
80383440: 24 01 00 40  ADDIU at, r0, 0x40 (64)
80383444: 15 21 00 05  BNE t1, at, 0x8038345c (pc + 0x14)  if ([sp + 0x26] != 0x40) goto 0x8038345c; /* if ([sp + 0x26] == 0x40) { */
80383448: 00 00 00 00  NOP

8038344c: 0c 0e 0c 74  JAL 0x803831d0 (-2143800880)        [sp + 0x20] = 0x803831d0(&[sp + 0x2c]);
80383450: 27 a4 00 2c  ADDIU a0, sp, 0x2c (44)

80383454: 10 00 00 2d  BEQ r0, r0, 0x8038350c (pc + 0xb4)  goto 0x8038350c: /* } else { */
80383458: af a2 00 20  SW v0, sp, 0x20 (32)

8038345c: 87 aa 00 26  LH t2, sp, 0x26 (38)
80383460: 24 01 00 43  ADDIU at, r0, 0x43 (67)
80383464: 15 41 00 06  BNE t2, at, 0x80383480 (pc + 0x18)  if ([sp + 0x26] != 0x43) goto 0x80383480; /* if ([sp + 0x26] == 0x43) { */
80383468: 00 00 00 00  NOP

8038346c: 87 a4 00 2a  LH a0, sp, 0x2a (42)
80383470: 0c 0b 8a 3b  JAL 0x802e28ec (-2144458516)        0x802e28ec([sp + 0x2a], &[sp + 0x2c])
80383474: 27 a5 00 2c  ADDIU a1, sp, 0x2c (44)

80383478: 10 00 00 24  BEQ r0, r0, 0x8038350c (pc + 0x90)  goto 0x8038350c; /* } else { */
8038347c: 00 00 00 00  NOP

80383480: 87 ab 00 26  LH t3, sp, 0x26 (38)
80383484: 24 01 00 44  ADDIU at, r0, 0x44 (68)
80383488: 15 61 00 05  BNE t3, at, 0x803834a0 (pc + 0x14)  if ([sp + 0x26] != 0x44) goto 0x803834a0; /* if ([sp + 0x26] == 0x44) { */
8038348c: 00 00 00 00  NOP

80383490: 0c 0e 0c 8a  JAL 0x80383228 (-2143800792)        0x80383228(&[sp + 0x2c])
80383494: 27 a4 00 2c  ADDIU a0, sp, 0x2c (44)

80383498: 10 00 00 1c  BEQ r0, r0, 0x8038350c (pc + 0x70)  goto 0x8038350c; /* } else { */
8038349c: 00 00 00 00  NOP

803834a0: 87 ac 00 26  LH t4, sp, 0x26 (38)
803834a4: 24 01 00 41  ADDIU at, r0, 0x41 (65)
803834a8: 15 81 00 05  BNE t4, at, 0x803834c0 (pc + 0x14)  if ([sp + 0x26] != 0x41) goto 0x803834c0; /* if ([sp + 0x26] == 0x41) { */
803834ac: 00 00 00 00  NOP

803834b0: 10 00 00 16  BEQ r0, r0, 0x8038350c (pc + 0x58)  goto 0x8038350c;
803834b4: 00 00 00 00  NOP

803834b8: 10 00 00 14  BEQ r0, r0, 0x8038350c (pc + 0x50)  goto 0x8038350c;
803834bc: 00 00 00 00  NOP

803834c0: 87 ad 00 26  LH t5, sp, 0x26 (38)
803834c4: 24 01 00 42  ADDIU at, r0, 0x42 (66)
803834c8: 15 a1 00 05  BNE t5, at, 0x803834e0 (pc + 0x14)  if ([sp + 0x26] != 0x42) goto 0x803834a0; /* if ([sp + 0x26] == 0x42) { */
803834cc: 00 00 00 00  NOP

803834d0: 10 00 00 10  BEQ r0, r0, 0x80383514 (pc + 0x40)  goto 0x80383514;
803834d4: 00 00 00 00  NOP

803834d8: 10 00 00 0c  BEQ r0, r0, 0x8038350c (pc + 0x30)  goto 0x8038350c;
803834dc: 00 00 00 00  NOP

803834e0: 87 ae 00 26  LH t6, sp, 0x26 (38)
803834e4: 29 c1 00 65  SLTI at, t6, 0x65 (101)
803834e8: 14 20 00 08  BNE at, r0, 0x8038350c (pc + 0x20)  if ([sp + 0x26] >= 0x65) goto 0x8038350c; THIS IS BACKWARDS and NOT FIXED
803834ec: 00 00 00 00  NOP

803834f0: 27 a4 00 2c  ADDIU a0, sp, 0x2c (44)
803834f4: 8f a5 00 20  LW a1, sp, 0x20 (32)
803834f8: 87 a6 00 26  LH a2, sp, 0x26 (38)
803834fc: 0c 0e 0c 1a  JAL 0x80383068 (-2143801240)        0x80383068(&[sp + 0x2c], [sp + 0x20], [sp + 0x26], &[sp + 0x30]);
80383500: 27 a7 00 30  ADDIU a3, sp, 0x30 (48)

80383504: 10 00 00 01  BEQ r0, r0, 0x8038350c (pc + 0x4)    goto 0x8038350c;
80383508: 00 00 00 00  NOP

8038350c: 10 00 ff ba  BEQ r0, r0, 0x803833f8 (pc - 0x118)  goto 0x803833f8;
80383510: 00 00 00 00  NOP

80383514: 8f af 00 34  LW t7, sp, 0x34 (52)
80383518: 11 e0 00 14  BEQ r0, t7, 0x8038356c (pc + 0x50)   if (![sp + 0x34]) goto 0x8038356c;
8038351c: 00 00 00 00  NOP

80383520: 85 f8 00 00  LH t8, t7, 0x0 (0)
80383524: 24 01 ff ff  ADDIU at, r0, 0xffffffff (-1)
80383528: 13 01 00 10  BEQ at, t8, 0x8038356c (pc + 0x40)   if (*[sp + 0x34] == -1) goto 0x8038356c;
8038352c: 00 00 00 00  NOP

80383530: 8f b9 00 34  LW t9, sp, 0x34 (52)
80383534: 87 28 00 00  LH t0, t9, 0x0 (0)
80383538: 05 00 00 09  BLTZ t0, 0x80383560 (pc + 0x24)      if (*[sp + 0x34] < 0) goto 0x80383560;
8038353c: 00 00 00 00  NOP

80383540: 29 01 00 1e  SLTI at, t0, 0x1e (30)               if (*[sp + 0x34] >= 0x1e) goto 0x80383560;
80383544: 10 20 00 06  BEQ r0, at, 0x80383560 (pc + 0x18)
80383548: 00 00 00 00  NOP

8038354c: 87 a4 00 2a  LH a0, sp, 0x2a (42)
80383550: 0c 0b 89 a4  JAL 0x802e2690 (-2144459120)         0x802e2690([sp + 0x28], [sp + 0x34]);
80383554: 8f a5 00 34  LW a1, sp, 0x34 (52)

80383558: 10 00 00 04  BEQ r0, r0, 0x8038356c (pc + 0x10)   goto 0x8038356c;
8038355c: 00 00 00 00  NOP

80383560: 87 a4 00 2a  LH a0, sp, 0x2a (42)
80383564: 0c 0b 89 05  JAL 0x802e2414 (-2144459756)         0x802e2414([sp + 0x28], [sp + 0x34]);
80383568: 8f a5 00 34  LW a1, sp, 0x34 (52)

8038356c: 3c 09 80 36  LUI t1, 0x8036 (32822)
80383570: 8d 29 11 6c  LW t1, t1, 0x116c (4460)
80383574: 3c 01 80 36  LUI at, 0x8036 (32822)
80383578: ac 29 11 74  SW t1, at, 0x1174 (4468)             *(0x80361174) = *(0x8036116c);

8038357c: 3c 0a 80 36  LUI t2, 0x8036 (32822)
80383580: 8d 4a 11 70  LW t2, t2, 0x1170 (4464)
80383584: 3c 01 80 36  LUI at, 0x8036 (32822)
80383588: ac 2a 11 78  SW t2, at, 0x1178 (4472)             *(0x80361178) = *(0x80361170);

8038358c: 10 00 00 01  BEQ r0, r0, 0x80383594 (pc + 0x4)
80383590: 00 00 00 00  NOP
80383594: 8f bf 00 14  LW ra, sp, 0x14 (20)
80383598: 27 bd 00 28  ADDIU sp, sp, 0x28 (40)
8038359c: 03 e0 00 08  JR ra
803835a0: 00 00 00 00  NOP



[sp + 0x28] == arg1
[sp + 0x2c] == arg2
[sp + 0x30] == arg3
[sp + 0x34] == arg4


0x803833b8(arg1, arg2, arg3, arg4)
{
    short lv1; /* sp + 0x26 */

    *(0x80361184) = 0;
    *(0x8038be90) = 0;
    *(0x8036116c) = 0;
    *(0x80361170) = 0;
    0x803825d0();
    for (;;) {
        [sp + 0x26] = *arg2
        [sp + 0x2c] += 2;
        if ([sp + 0x26] < 0x40) {
            0x80383068(&[sp + 0x2c], [sp + 0x20], [sp + 0x26], &[sp + 30]);
        } else if ([sp + 0x26] == 0x40) {
            [sp + 0x20] = 0x803831d0(&[sp + 0x2c]);
        } else if ([sp + 0x26] == 0x43) {
            0x802e28ec([sp + 0x2a], &[sp + 0x2c])
        } else if ([sp + 0x26] == 0x44) {
            0x80383228(&[sp + 0x2c])
        } else if ([sp + 0x26] == 0x41) {
            continue;
        } else if ([sp + 0x26] == 0x42) {
            break;
        } else if ([sp + 0x26] < 0x65) {
            0x80383068(&[sp + 0x2c], [sp + 0x20], [sp + 0x26], &[sp + 0x30]);
        }
    }
    80383514: if (![sp + 0x34]) goto 0x8038356c;
    if (*[sp + 0x34] == -1) goto 0x8038356c;
    if (*[sp + 0x34] < 0) goto 0x80383560;
    if (*[sp + 0x34] >= 0x1e) goto 0x80383560;
    0x802e2690([sp + 0x28], [sp + 0x34]);
    goto 0x8038356c;
    0x802e2414([sp + 0x28], [sp + 0x34]);
    *(0x80361174) = *(0x8036116c);
    *(0x80361178) = *(0x80361170);
}

0x803833b8(int arg1, short *arg2, char *arg3, short *arg4)
{
    long lv2;  /* sp + 0x20 */ /* pointer to vertices */
    short lv1; /* sp + 0x26 */
    //short lv3; /* sp + 0x2a */

    *(0x80361184) = 0;
    *(0x8038be90) = 0;
    *(0x8036116c) = 0;
    *(0x80361170) = 0; //reset next index of run time solidity array
    0x803825d0();
    for (;;) {
        lv1 = *arg2;
        arg2 ++;
        
        if (lv1 < 0x40) { /* Solidity triangles */
            0x80383068(&arg2, lv2, lv1, &arg3);
        } else if (lv1 == 0x40) {
            lv2 = 0x803831d0(&arg2);
        } else if (lv1 == 0x43) { /* objects */
            0x802e28ec(arg1, &arg2)
        } else if (lv1 == 0x44) { /* water */
            0x80383228(&arg2)
        } else if (lv1 == 0x41) { /* nop */
            continue;
        } else if (lv1 == 0x42) {
            break;
        } else if (lv1 >= 0x65) { //FIXED /* Solidity triangles */
            0x80383068(&arg2, lv2, lv1, &arg3);
        }
    }
    
   
    if (arg4 && *arg4 != -1) {
        if (*arg4 >= 0 && *arg4 < 0x1e) {
            0x802e2690(arg1, arg4);
        } else {
            0x802e2414(arg1, arg4);
        }
    }
    *(0x80361174) = *(0x8036116c);
    *(0x80361178) = *(0x80361170);
}
